package inet.app.vod.activity.search;

import inet.app.vod.activity.R;
import inet.app.vod.activity.common.BaseActivity;
import inet.app.vod.config.AppConstants;
import inet.app.vod.view.MyViewPagerHeader;

import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

public class SearchActivity extends BaseActivity {

	private ViewPager mViewPager;
	private SearchPagerAdapter mPagerAdapter;
	private MyViewPagerHeader mHeader;

	private static final ArrayList<String> mCategorySearch;
	private static final ArrayList<String> mCategorySearchHint;
	static {
		mCategorySearch = new ArrayList<String>();
		mCategorySearch.add("Phim");
		mCategorySearch.add("Clip");
		mCategorySearch.add("News");
		mCategorySearch.add("Fun");

		mCategorySearchHint = new ArrayList<String>();
		for (String str : mCategorySearch) {
			mCategorySearchHint.add(new StringBuffer("Search ").append(str)
					.toString());
		}
	}

	private void initModels() {
		mPagerAdapter = new SearchPagerAdapter(this,
				getSupportFragmentManager(), initFragments());
	}

	private void initViews() {
		mViewPager = (ViewPager) findViewById(R.id.view_pager);
		mViewPager.setAdapter(mPagerAdapter);
		mViewPager.setOffscreenPageLimit(4);

		String[] titles = new String[] { "Phim", "Clip", "News", "Fun" };
		mHeader = (MyViewPagerHeader) findViewById(R.id.viewpager_header);
		mHeader.attachToViewPager(mViewPager, titles,
				new OnPageChangeListener() {

					@Override
					public void onPageSelected(int position) {
						switch (position) {
						case 0:
							mSlideMenu
									.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
							break;
						default:
							mSlideMenu
									.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
							break;
						}
					}

					@Override
					public void onPageScrolled(int arg0, float arg1, int arg2) {

					}

					@Override
					public void onPageScrollStateChanged(int arg0) {

					}
				});
		setTitle("Search");
	}

	private Fragment[] initFragments() {
		Fragment[] fragments = new Fragment[4];
		fragments[0] = SearchFragment.newInstance(AppConstants.ID_IPHIM);
		fragments[1] = SearchFragment.newInstance(AppConstants.ID_ICLIP);
		fragments[2] = SearchFragment.newInstance(AppConstants.ID_INEWS);
		fragments[3] = SearchFragment.newInstance(AppConstants.ID_IFUN);
		return fragments;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search);
		initUIBase();
		initModels();
		initViews();
	}

	@Override
	public void setTagMenu() {
		mTagMenu = AppConstants.MENU_SEARCH;
	}

}
